<template>
	<view class="question-page">
		<!-- #ifdef APP -->
		<u-navbar title="添加联系方式" :autoBack="true" :placeholder="true">></u-navbar>
		<!-- #endif -->
		<view class="contentBox">
			<view class="page-title">
				我们会保护你的隐私，联系方式只展示给审核人员和付费用户查看;<br/>
				通过认证后，你可以在设置中修改微信的查看方式
			</view>
			<view class="content-box">
				<view class="title">
					<image src="../../static/user/icon_wx.png" class="icon"></image> 微信号
				</view>
				<view class="input-box">
					<u-input v-model="userInfo.wechat" placeholder="请输入微信号" :clearable="true" border="none"
						:customStyle="{height:'88rpx'}"></u-input>
				</view>
			</view>
			<view class="content-box">
				<view class="title">
					<image src="../../static/user/icon_ewm.png" class="icon"></image> 微信二维码
				</view>
				<view class="avatar-box">
					<view class="default-avatar">
						<uploadImage @uploadSuccess='uploadSuccess' :fileList="fileList" name="image" :maxCount='1'
							width="192rpx" height="192rpx"></uploadImage>
					</view>
				</view>
			</view>
			<view class="button-group">
				<view class="button1" @click="$u.throttle(updateUserInfo,2000)">提交</view>
			</view>
		</view>

		<view style="height: 20rpx;"></view>
	</view>
</template>

<script>
	import uploadImage from '@/components/UploadImage.vue';
	export default {
		data() {
			return {
				userInfo: {
					wechat: '',
					wechat_img: '',
				},
				fileList: []
			}
		},
		components: {
			uploadImage: uploadImage
		},
		onLoad() {
			this.getUserInfo()
		},
		methods: {
			getUserInfo() {
				this.$Api['user'].getUserInfo().then(res => {
					this.userInfo = {
						wechat: res.data.wechat,
						wechat_img: res.data.wechat_img,
					}
					if (res.data.wechat_img != '') {
						this.fileList = [{
							url: this.$OssUrl(res.data.wechat_img)
						}]
					}
				})
			},
			//修改用户信息
			updateUserInfo() {
				if (this.userInfo.wechat == '') {
					return this.$Toast('请输入微信号')
				}
				if (this.userInfo.wechat_img == '') {
					return this.$Toast('请选择微信二维码')
				}
				this.$Api['user'].updateUserInfo(this.userInfo).then(res => {
					uni.navigateBack({
						delta: 1
					})
				})
			},
			uploadSuccess(e) {
				this.userInfo.wechat_img = e.fileList
			}
		}
	}
</script>

<style lang="less" scoped>
	.question-page {
		width: 100%;
		min-height: 100vh;
		background-color: #f7f8fa;
		position: relative;

		.contentBox {
			min-height: 80vh;
			margin: 20rpx 34rpx;
			padding: 38rpx 40rpx 38rpx;
			box-shadow: 0rpx 4rpx 32rpx 0rpx #FFF0FD;
			border-radius: 32rpx;
			background: linear-gradient(180deg, #FFDAF5 0%, #FFFFFF 5%);

			.page-title {
				font-size: 26rpx;
				color: #AFAFAF;
			}

			.content-box,
			.image-box {
				margin-top: 40rpx;
				flex: 1;

				.avatar-box {
					display: grid;
					grid-template-columns: repeat(3, 1fr);
					grid-auto-flow: row;
					grid-gap: 20rpx;

					.default-avatar {
						width: 192rpx;
						height: 192rpx;
						position: relative;
						border-radius: 16rpx;
						overflow: hidden;

						.label {
							position: absolute;
							left: 0;
							top: 0;
							z-index: 1;
							width: 76rpx;
							height: 28rpx;
							font-size: 20rpx;
							color: #FFFFFF;
							text-align: center;
							background: #F169F6;
							border-radius: 16rpx 0rpx 16rpx 0rpx;
						}

						.select {
							position: absolute;
							right: 0;
							top: 0;
							z-index: 1;
							width: 32rpx;
							height: 32rpx;
						}

						.avatar {
							width: 100%;
							height: 100%;
						}
					}
				}

				.title {
					display: flex;
					align-items: center;
					font-size: 28rpx;
					margin: 42rpx 0 20rpx;

					.icon {
						width: 28rpx;
						height: 28rpx;
						margin-right: 8rpx;
					}
				}


				.input-box {
					height: 88rpx;
					line-height: 88rpx;
					background: #F6F6F6;
					border-radius: 16rpx;
					flex: 1;
					display: flex;
					align-items: center;
					padding: 0 20rpx;

					.random {
						display: flex;
						align-items: center;
						font-size: 28rpx;
						color: #F16AF6;
						margin: 0 28rpx;

						.image {
							width: 36rpx;
							height: 36rpx;
							margin-right: 8rpx;
						}
					}
				}
			}

			.button-group {
				.button1 {
					margin: 160rpx auto 0;
					width: 628rpx;
					height: 88rpx;
					font-weight: bold;
					font-size: 30rpx;
					color: #FFFFFF;
					text-align: center;
					line-height: 88rpx;
					background: linear-gradient(135deg, #FE93BF 0%, #A27AFF 100%);
					box-shadow: 0rpx 4rpx 10rpx 0rpx #FDC4FF;
					border-radius: 44rpx;
				}
			}
		}
	}
</style>